<?php

namespace app\api\model;

use app\common\model\BaseModel;
use think\model\concern\SoftDelete;

class OrderContinue extends BaseModel
{

    use SoftDelete;

    

    // 表名
    protected $name = 'order_continue';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [

    ];


    //订单状态处理
    public static function fetchStatus($status = null){
        $data =  [
            1 => '待支付',
            2 => '已支付',
            3 => '已取消',
            4 => '已退款',
        ];
        if (isset($data[$status])) {
            return $data[$status];
        }else{
            return $data;
        }
    }

    //支付方式
    public static function fetchPayType($pay_type = null){
        $data =  [
            1 => '微信支付',
            2 => '支付宝支付',
        ];
        if (isset($data[$pay_type])) {
            return $data[$pay_type];
        }else{
            return $data;
        }
    }

    //取消原因
    public static function fetchCancelReason($cancel_reason = null){
        $data =  [
            1 => '行程有变',
            2 => '不想租了',
            3 => '重新下单',
            4 => '价格原因',
            5 => '其他原因',
        ];
        if (isset($data[$cancel_reason])) {
            return $data[$cancel_reason];
        }else{
            return $data;
        }
    }

    public function user(){
        return $this->hasOne('user', 'id', 'user_id')->joinType('left');
    }
    public function merchantCar(){
        return $this->hasOne('merchant_car', 'id', 'merchant_car_id')->joinType('left');
    }
    public function users(){
        return $this->hasOne('user', 'id', 'user_id')->bind(['username','avatar','truename','id_card'])->joinType('left');
    }

    //生成唯一退款号
    public static function getOutRefundNo(){
        $out_refund_no = sys_create_orderno(4);
        $order = self::where('out_refund_no', $out_refund_no)->count();
        if($order){
            return self::getOutRefundNo();
        }
        return $out_refund_no;
    }

    //生成唯一订单号
    public static function getOutTradeNo(){
        $out_trade_no = sys_create_orderno(1);
        $order = self::where('out_trade_no', $out_trade_no)->count();
        if($order){
            return self::getOutTradeNo();
        }
        return $out_trade_no;
    }
}
